package com.ServletDemo.servletText07;

import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.Map;

@WebServlet("/servletDemo11")
public class servletDemo11 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader bu = new BufferedReader(new FileReader("d:\\stu.txt"));
        ArrayList<Student> list = new ArrayList<>();
        Student stu = new Student();
        resp.setContentType("text/html;charset=UTF-8");
        String by;
        while ((by = bu.readLine()) != null) {
            String[] sp = by.split(",");
            stu.setUsername(sp[0]);
            stu.setAge(Integer.parseInt(sp[1]));
            stu.setScore(Integer.parseInt(sp[2]));
            list.add(stu);
        }

        PrintWriter wr = resp.getWriter();
        for (Student student : list) {
           wr.write(student.getUsername()+","+student.getAge()+","+student.getScore());
           wr.write("<br>");

        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
